<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
	.tree-node {padding:0;}
</style>
<script type="text/javascript">
	$(function() {
		$('#toolbar_tagTable').toolbar({buttons:[
           	{name:'add',iconCls:'icon-add',text:'添加文章广告'},
           	{name:'addAuthor',iconCls:'icon-add',text:'添加大咖广告'},
           	{name:'addCompany',iconCls:'icon-add',text:'添加公司黄页广告'},
           	{name:'addProject',iconCls:'icon-add',text:'添加招商广告'},
        	{name:'addBanner',iconCls:'icon-add',text:'添加首页中部滑动广告'},
       		{name:'reload',iconCls:'icon-reload',text:'刷新'}
      	],handler:handler});
	    $('#tag_treegrid').datagrid({
    		url:'page',
    		pagination:true,
    		singleSelect:true,
    		pageSize:20,
    		rownumbers:true,
    		striped:true,
    		fitColumns:true,
    		fit:true,
    		idField:'id',
    		treeField:'tagName',
    		toorbar:'#toolbar_tagTable',
    		columns:[[
        		{field:'id',title:'id'},
        		{field:'title',title:'标题',width:'10%',align:'center'},
        		{field:'type',title:'广告类型',formatter:function(v,r,i){
        			var typeName = "栏目介绍";
        			if(r.type == "1"){
        				typeName = "文章"
        			} 
        			if (r.type == "5") {
        				typeName = "大咖广告"
        			}
        			if (r.type == "7") {
        				typeName = "第三方链接"
        			}
        			if (r.type == "9") {
        				typeName = "纯图片"
        			}
        			if (r.type == "11") {
        				typeName = "招商详情"
        			}
        			return typeName;
        		}},
        		{field:'targetplace',title:'广告目标',formatter:function(v,r,i){
        			var typeName = "首页";
        			if (r.targetplace == 2) {
        				typeName = "招商"
        			}
        			if (r.targetplace == 3) {
        				typeName = "黄页"
        			}
        			if (r.targetplace == 4) {
        				typeName = "首页中部滑动广告"
        			}
        			return typeName;
        		}},
        		{field:'imgurl',title:'图片的url',},
        		{field:'link',title:'广告的链接'},
        		{field:'description',title:'广告的描述',width:'30%'},
        		{field:'-',title:'操作',formatter:function(v,r,i){
        			var action = '<a href="#" onclick="toEdit('+r.id+','+r.targetplace+');">编辑</a>';
        			if(r.enabled == '1'){
        				action=action + ' <a style="color:red;" href="#" onclick="enabled('+r.id+',3,'+r.targetplace+');">下架</a>';
        			} else {
        				action=action + ' <a style="" href="#" onclick="enabled('+r.id+',1,'+r.targetplace+');">上架</a>';
        			}
       				action=action + ' <a style="" href="#" onclick="del('+r.id+');">删除</a>';
					return action;
				}}
    		]]
		 });
	    
	    
		function handler() {
			switch(this.name) {
				case 'add': toAdd();break;
				case 'addAuthor': toAddAuthor();break;
				case 'addCompany': toAddCompany();break;
				case 'addProject': toAddProject();break;
				case 'addBanner': toAddBanner();break;
				//case 'reload': toEdit(reload);break;
				case 'reload': toReload();break;
				case 'edit': toEdit();break;
			}
		}
		function toAdd() {
			show({code:'tag_info_add',title:'添加标签信息',iconCls:'icon-add',uri:'add',width:700,height:800,
				options : {
					success : function(data) { 
						 $('#tag_treegrid').datagrid('reload'); 
					}
				}
			});
		}
		function toAddProject() {
			show({code:'tag_info_addProject',title:'添加招商',iconCls:'icon-add',uri:'addProject',width:700,height:800,
				options : {
					success : function(data) { 
						 $('#tag_treegrid').datagrid('reload'); 
					}
				}
			});
		}
		function toAddAuthor() {
			show({code:'tag_info_addAuthor',title:'添加作者推荐广告',iconCls:'icon-add',uri:'addAuthor',width:700,height:800,
				options : {
					success : function(data) { 
						 $('#tag_treegrid').datagrid('reload'); 
					}
				}
			});
		}
		function toAddCompany() {
			show({code:'tag_info_addAuthor',title:'添加公司黄页广告',iconCls:'icon-add',uri:'addCompany',width:700,height:800,
				options : {
					success : function(data) { 
						 $('#tag_treegrid').datagrid('reload'); 
					}
				}
			});
		}
		function toAddBanner() {
			show({code:'tag_info_addAuthor',title:'添加首页中部滑动广告',iconCls:'icon-add',uri:'addBanner',width:700,height:800,
				options : {
					success : function(data) { 
						 $('#tag_treegrid').datagrid('reload'); 
					}
				}
			});
		}
	});
	
	//刷行
	function toReload(){
		 $('#tag_treegrid').datagrid('reload');
	}
	
	function toEdit(item,targetplace) {
		show({code:'tag_info_edit',title:'编辑标签信息',iconCls:'icon-edit',uri:'edit?id='+item+'&targetplace='+targetplace,width:700,height:800,
			options : {
				success : function(data) { 
					 $('#tag_treegrid').datagrid('reload'); 
				}
			}
		});
	}
	
	//更新可用标记
	function enabled(id,enabled,targetplace){
		var parms = {};
		parms.id = id;
		parms.enabled = enabled;
		parms.targetplace = targetplace
		$.post('enabled',parms,function(r){
			if(r.code>0){
				$('#tag_treegrid').datagrid('reload'); 
			} else {
				$prompt(r.msg,null);
			}
		},'json');
	}
	
	function del(id){
		var parms = {};
		parms.id = id;
		$.post('delete',parms,function(r){
			if(r.code>0){
				$('#tag_treegrid').datagrid('reload'); 
			};
		},'json');
	}
	
</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north',border:false">
			<fieldset>
    		<legend>查询信息</legend>
    		<table>
    			<tr>
    				<td>名称:<input class="easyui-textbox" data-options="prompt:'请输入标签名称'" ></td>
    				<td>
    					添加时间:
				<input class="easyui-combobox" 
					name="language"
					data-options="
						url:'',
						method:'get',
						valueField:'id',
						textField:'text',
						panelHeight:'auto'">
    				</td>
    				<td><a href="a_searchTag" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
    			</tr>
    		</table>
  			</fieldset>
		</div>
  		<div data-options="region:'center',border:false" style="padding-bottom: 33px">
  			
        	<div id="toolbar_tagTable" class="toolbar"></div>
  			<table id="tag_treegrid" style="width:100%;"></table>
		</div>
	</div>
</body>
</html>